package com.diandiansong.app.entity;

import android.content.Context;

import com.google.gson.annotations.SerializedName;

import diandiansong.library.utils.AFile;
import diandiansong.library.utils.BaseEntity;

public class LoginInfo extends BaseEntity {

    private static final String KEY_PWD = "PWD";

    public static void savePwd(Context context, String message) {
        AFile aFile = AFile.get(context, KEY_PWD);
        aFile.put(KEY_PWD, message);
    }

    public static String getPwd(Context context) {
        AFile aFile = AFile.get(context, KEY_PWD);
        return aFile.getAsString(KEY_PWD);
    }

    private static final String KEY_PHONE = "PHONE";

    public static void savePhone(Context context, String message) {
        AFile aFile = AFile.get(context, KEY_PHONE);
        aFile.put(KEY_PHONE, message);
    }

    public static String getPhone(Context context) {
        AFile aFile = AFile.get(context, KEY_PHONE);
        return aFile.getAsString(KEY_PHONE);
    }

    private static final String KEY_TOKEN = "TOKEN";

    public static void saveToken(Context context, String message) {
        AFile aFile = AFile.get(context, KEY_TOKEN);
        aFile.put(KEY_TOKEN, message);
    }

    public static void clearToken(Context context) {
        saveToken(context, "");
        savePwd(context, "");
    }

    public static boolean hasToken(Context context) {
        String token = getToken(context);
        return token != null && !token.isEmpty();
    }

    public static String getToken(Context context) {
        AFile aFile = AFile.get(context, KEY_TOKEN);
        return aFile.getAsString(KEY_TOKEN);
    }

    /**
     * data :
     * {"token":"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMzIxMjMxMjMxMSIsImlzcyI6Imh0dHA6XC9cL2gxLm1vYmlsZWtvdWRhaS5jb21cL2FwaVwvYXV0aFwvbG9naW4iLCJpYXQiOiIxNTMxMjkxMjgyIiwiZXhwIjoiMTUzMTg5NjA4MiIsIm5iZiI6IjE1MzEyOTEyODIiLCJqdGkiOiIwMGU0OGZlMjc5NDhjNTVmZDRlN2Y3YjBkODBiYjA3NSJ9.u6RIl1QU-wAHTrcJe8VtKb6su7JAXPFUkk8q2g0LqN8"}
     */

    @SerializedName("data")
    private Data data;

    public Data getData() {
        return data;
    }

    public void setData(Data data) {
        this.data = data;
    }

    public static class Data {
        /**
         * token :
         * eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMzIxMjMxMjMxMSIsImlzcyI6Imh0dHA6XC9cL2gxLm1vYmlsZWtvdWRhaS5jb21cL2FwaVwvYXV0aFwvbG9naW4iLCJpYXQiOiIxNTMxMjkxMjgyIiwiZXhwIjoiMTUzMTg5NjA4MiIsIm5iZiI6IjE1MzEyOTEyODIiLCJqdGkiOiIwMGU0OGZlMjc5NDhjNTVmZDRlN2Y3YjBkODBiYjA3NSJ9.u6RIl1QU-wAHTrcJe8VtKb6su7JAXPFUkk8q2g0LqN8
         */

        @SerializedName("token")
        private String token;

        public String getToken() {
            return token;
        }

        public void setToken(String token) {
            this.token = token;
        }
    }
}
